package evocarcassonne.tileseteditor.ui.swing.panels.zones;

import evocarcassonne.core.board.locations.Zone;
import evocarcassonne.core.utils.Card;
import java.awt.Component;
import javax.swing.JRadioButton;

public class RoadPanel extends javax.swing.JPanel {

    private boolean userAction = false;

    public RoadPanel() {
        initComponents();
    }

    public RoadPanel(Zone zone) {
        
        this();
        this.zone = zone;
        title = "Road";
        
        switch (zone.card) {
            case Card.N:
                title += " - North";
                break;
            case Card.E:
                title += " - East";
                break;
            case Card.S:
                title += " - South";
                break;
            case Card.W:
                title += " - Ouest";
                break;
        }

        //init GUI
        userAction = false;

        deadEndRadio.setSelected(zone.isDeadEnd());

        if (zone.getTouch() != -1) {
            contactRadio.setSelected(true);

            switch (zone.getTouch()) {
                case Card.N:
                    break;
                case Card.E:
                    break;
                case Card.S:
                    break;
                case Card.W:
                    break;
            }

        } else {
            contactRadio.setSelected(false);
        }
        userAction = true;
    }

    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        singleButtonGroup = new javax.swing.ButtonGroup();
        optionsButtonGroup = new javax.swing.ButtonGroup();
        optionsZone = new javax.swing.JPanel();
        deadEndRadio = new javax.swing.JRadioButton();
        contactZoneCombo = new javax.swing.JComboBox();
        contactRadio = new javax.swing.JRadioButton();
        contactZoneLabel = new javax.swing.JLabel();
        jRadioButton3 = new javax.swing.JRadioButton();
        optionsGroup = new javax.swing.JPanel();
        jRadioButton1 = new javax.swing.JRadioButton();
        jRadioButton2 = new javax.swing.JRadioButton();

        optionsZone.setBorder(javax.swing.BorderFactory.createTitledBorder("optionsZone"));

        singleButtonGroup.add(deadEndRadio);
        deadEndRadio.setSelected(true);
        deadEndRadio.setText("DeadEnd");
        deadEndRadio.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                deadEndRadioItemStateChanged(evt);
            }
        });

        contactZoneCombo.setEnabled(false);

        singleButtonGroup.add(contactRadio);
        contactRadio.setText("Contact :");
        contactRadio.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                contactRadioItemStateChanged(evt);
            }
        });

        contactZoneLabel.setText("Zone :");
        contactZoneLabel.setEnabled(false);

        singleButtonGroup.add(jRadioButton3);
        jRadioButton3.setText("Inn");
        jRadioButton3.setEnabled(false);

        javax.swing.GroupLayout optionsZoneLayout = new javax.swing.GroupLayout(optionsZone);
        optionsZone.setLayout(optionsZoneLayout);
        optionsZoneLayout.setHorizontalGroup(
            optionsZoneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(optionsZoneLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(optionsZoneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(deadEndRadio)
                    .addGroup(optionsZoneLayout.createSequentialGroup()
                        .addComponent(contactRadio)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(contactZoneLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(contactZoneCombo, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jRadioButton3))
                .addContainerGap(139, Short.MAX_VALUE))
        );
        optionsZoneLayout.setVerticalGroup(
            optionsZoneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(optionsZoneLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(deadEndRadio)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(optionsZoneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(contactRadio)
                    .addComponent(contactZoneCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(contactZoneLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jRadioButton3)
                .addContainerGap(86, Short.MAX_VALUE))
        );

        optionsGroup.setBorder(javax.swing.BorderFactory.createTitledBorder("optionsGroup"));

        optionsButtonGroup.add(jRadioButton1);
        jRadioButton1.setText("Inn");
        jRadioButton1.setEnabled(false);

        optionsButtonGroup.add(jRadioButton2);
        jRadioButton2.setText("Blocked");

        javax.swing.GroupLayout optionsGroupLayout = new javax.swing.GroupLayout(optionsGroup);
        optionsGroup.setLayout(optionsGroupLayout);
        optionsGroupLayout.setHorizontalGroup(
            optionsGroupLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(optionsGroupLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(optionsGroupLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jRadioButton1)
                    .addComponent(jRadioButton2))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        optionsGroupLayout.setVerticalGroup(
            optionsGroupLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(optionsGroupLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jRadioButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jRadioButton2)
                .addContainerGap(103, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(optionsZone, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(optionsGroup, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(optionsZone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(optionsGroup, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void contactRadioItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_contactRadioItemStateChanged
        boolean value = ((JRadioButton) evt.getSource()).isSelected();
        contactZoneCombo.setEnabled(value);
        contactZoneLabel.setEnabled(value);
    }//GEN-LAST:event_contactRadioItemStateChanged

    private void deadEndRadioItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_deadEndRadioItemStateChanged

        if (userAction) {

            boolean value = ((JRadioButton) evt.getSource()).isSelected();
            zone.setDeadEnd(value);
        }
        userAction = true;

    }//GEN-LAST:event_deadEndRadioItemStateChanged
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JRadioButton contactRadio;
    private javax.swing.JComboBox contactZoneCombo;
    private javax.swing.JLabel contactZoneLabel;
    private javax.swing.JRadioButton deadEndRadio;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JRadioButton jRadioButton3;
    private javax.swing.ButtonGroup optionsButtonGroup;
    private javax.swing.JPanel optionsGroup;
    private javax.swing.JPanel optionsZone;
    private javax.swing.ButtonGroup singleButtonGroup;
    // End of variables declaration//GEN-END:variables

    public String getParentTitle() {
        return title;
    }
    Zone zone;
    String title;

    public void enabledGroupOptions(boolean b) {

        optionsGroup.setEnabled(b);

        for (Component comp : optionsGroup.getComponents()) {
            comp.setEnabled(b);
        }
    }
}
